package cn.pw.test.com.news.adapter;

import android.view.View;
import android.widget.ImageView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.pw.test.com.news.R;
import cn.pw.test.com.news.bean.ArticleBean;
import tech.com.commoncore.manager.GlideManager;

import static cn.pw.test.com.news.manager.NewsPathManger.NEWS_ARTICLE_DETAIL;
import static cn.pw.test.com.news.manager.NewsPathManger.NEWS_ARTICLE_KEY;

public class ArticleAdapter extends BaseQuickAdapter<ArticleBean, BaseViewHolder> {

    public ArticleAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, final ArticleBean item) {
        helper.setText(R.id.article_item_title_tx, item.getPost_title());
        helper.setText(R.id.article_item_date_tx, item.getCreate_time());
        ImageView thumbnailImg = helper.itemView.findViewById(R.id.article_item_img);

        String imgUrl = "";
        if (item.getMore() != null) {
            imgUrl = item.getMore().getThumbnai();
        }
        GlideManager.loadImg(imgUrl, thumbnailImg, R.mipmap.news_icon_placeholder);

        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ARouter.getInstance().build(NEWS_ARTICLE_DETAIL)
                        .withInt(NEWS_ARTICLE_KEY, item.getId())
                        .greenChannel()
                        .navigation();
//                SQLGlobal.getImp().addArticleHistory(item.title, item.images, item.content_url);
            }
        });
    }
}
